package com.yiyuan.app.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.yiyuan.app.entity.po.OAppVersionPO;
import com.yiyuan.app.mapper.OAppVersionMapper;
import org.springframework.stereotype.Repository;

@Repository
public class OAppVersionDAO extends BaseDAO<OAppVersionMapper, OAppVersionPO> {

    public OAppVersionPO findLatestVersion(String appType) {
        LambdaQueryWrapper<OAppVersionPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OAppVersionPO::getAppType, appType);
        queryWrapper.orderByDesc(OAppVersionPO::getVersionNo);
        queryWrapper.last("limit 0,1");
        return getBaseMapper().selectOne(queryWrapper);
    }

    public OAppVersionPO findLatestUpdateVersion(String appType) {
        LambdaQueryWrapper<OAppVersionPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OAppVersionPO::getAppType, appType);
        queryWrapper.eq(OAppVersionPO::getIsMustUpdate, Boolean.TRUE);
        queryWrapper.orderByDesc(OAppVersionPO::getVersionNo);
        queryWrapper.last("limit 0,1");
        return getBaseMapper().selectOne(queryWrapper);
    }
}
